/*!
 * \file database_exploitation.c
 * \author Cyril Henriot (elodiecyril.wedding@gmail.com)
 * 
 * This file contains implementation to encode and manipulate exploitations through EXPLOITATION type.
 */

#include<stdio.h>
#include<string.h>
#include <assert.h>
#include <stdlib.h>
#include "../../includes/database_exploitation.h"
#include "../debug.h"


/*! \brief Create a new instance of an object EXPLOITATION.
 *  \return 0 if success, otherwise an error code (type EXPLOITATION_ERROR)
 * 
 * All Fields are initiate at zero.
 */
int EXPLOITATION_Create(PTR_EXPLOITATION *PtrExploitation)
{
  // Pre conditions
  assert(*PtrExploitation == NULL);
  
  // Actions
  *PtrExploitation = (PTR_EXPLOITATION) malloc( sizeof(EXPLOITATION));
  if (PtrExploitation == NULL)
  {
    return EXPLOITATION_ERROR_1_MALLOC_INIT_FAILED;
  }
  
  (*PtrExploitation) -> nom = "\0";
  (*PtrExploitation) -> qualite = Moyenne;
  
  // Post conditions
  assert(*PtrExploitation != NULL);
  
  return EXPLOITATION_OPERATION_SUCCESS;
}


/*! \brief Destroy an instance of an object EXPLOITATION.
 *  \return 0 if success, otherwise an error code
 * 
 * PtrExploitation is set at NULL
 */
int EXPLOITATION_Destroy(PTR_EXPLOITATION *PtrExploitation)
{
  // Pre conditions
  assert(*PtrExploitation != NULL);
  
  free(*PtrExploitation);
  *PtrExploitation = NULL;
  
  // Post conditions
  assert(*PtrExploitation == NULL);
  
  return EXPLOITATION_OPERATION_SUCCESS;
}


/*! \brief Get exploitation name from an instance of EXPLOITATION.
 *  \return 0 if success, otherwise an error code
 */
int EXPLOITATION_GetNom (PTR_EXPLOITATION PtrExploitation, char nom[])
{   
  // Précondition
  assert( PtrExploitation != NULL );
  
  //Actions
  strcpy( nom, PtrExploitation -> nom );
  
  // Post condition
  assert( PtrExploitation != NULL );
  
  return EXPLOITATION_OPERATION_SUCCESS;
}


/*! \brief Set exploitation name to an instance of EXPLOITATION.
 *  \return 0 if success, otherwise an error code
 */
int EXPLOITATION_SetNom (PTR_EXPLOITATION PtrExploitation, char nom[])
{
  // Précondition
  assert(PtrExploitation != NULL);
  
  // Actions
  nom[254] = '\0';
  strcpy( PtrExploitation -> nom, nom );
  
  // Post condition
  assert(PtrExploitation != NULL);
  
  return EXPLOITATION_OPERATION_SUCCESS;
}


/*! \brief Get exploitation qualite from an instance of EXPLOITATION.
 *  \return 0 if success, otherwise an error code
 */
int EXPLOITATION_GetQualite (PTR_EXPLOITATION PtrExploitation, EXPLOITATION_QUALITE *qualite)
{ 
  // Précondition
  assert( PtrExploitation != NULL );
  
  //Actions
  *qualite = PtrExploitation -> qualite;
  
  // Post condition
  assert( PtrExploitation != NULL );
  
  return EXPLOITATION_OPERATION_SUCCESS;
}


/*! \brief Set exploitation qualite to an instance of EXPLOITATION.
 *  \return 0 if success, otherwise an error code
 */
int EXPLOITATION_SetQualite (PTR_EXPLOITATION PtrExploitation, EXPLOITATION_QUALITE *qualite)
{
  // Précondition
  assert(PtrExploitation != NULL);

  // Actions
  (*PtrExploitation) -> nom[254] = "\0";
  (*PtrExploitation) -> qualite = *qualite;

  // Post condition
  assert(PtrExploitation != NULL);

  return EXPLOITATION_OPERATION_SUCCESS;
}
